package com.mh.caipiao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mh.caipiao.entity.CaiPiaoEntity;
import com.mh.caipiao.service.CaiPiaoService;
import com.mh.mh.util.MyUtil;
import com.mh.mh.util.WuXingRelationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.*;
//import cn.hutool.core.date.chinese.ChineseDate;

/**
 * 彩票预测
 */
@Slf4j
@Component
public class CaiPiaoStart {

    @Autowired
    protected CaiPiaoService caiPiaoService;

    @Autowired
    protected WuXingRelationUtil wuXingRelationUtil;


//    @PostConstruct
    public void test(){

        int czx = 4;// 0天干，1地支，2农历，3阳历，4纳音
        int codeIndex = 4;// 0代表第一个号码，总共5个号码
        String start = "2023-05-08";
        String end = "2023-06-21";

        List<CaiPiaoEntity> list = caiPiaoService.list(
                new LambdaQueryWrapper<CaiPiaoEntity>().ge(CaiPiaoEntity::getKjDate, start)
                        .le(CaiPiaoEntity::getKjDate, end)
//                        .orderByDesc(CaiPiaoEntity::getKjDate)
        );

        // 水平对比
        sp(list,czx, codeIndex);
        // 相邻两行对比
//        xiangling(list,czx, codeIndex, 1);

        // 环比,就是间隔，相邻就是1，相隔一行就是2，以此类推。注意取值时间范围
//        xiangling(list,czx, codeIndex, 2);

    }


    /**
     * 水平对比
     */
    public void sp(List<CaiPiaoEntity> list, int czxMax, int codeIndexMax){
        Map<String, Integer> cntMap = new HashMap<>();

        for(int i = 0; i<= czxMax; i++){
            int czx = i;
            if(czx == 0){
                System.out.println("========= 0天干 =========");
            }else if(czx == 1){
                System.out.println("========= 1地支 =========");
            }else if(czx == 2){
                System.out.println("========= 2农历 =========");
            }else if(czx == 3){
                System.out.println("========= 3阳历 =========");
            }else if(czx == 4){
                System.out.println("========= 4纳音 =========");
            }
            for(int j = 0; j<= codeIndexMax; j++){
                int codeIndex = j;
                System.out.println("----- "+j+" ----- ");

                for(CaiPiaoEntity caiPiaoEntity : list){
                    String kjDate = caiPiaoEntity.getKjDate();
                    String tg = caiPiaoEntity.getTg();
                    String dz = caiPiaoEntity.getDz();
                    String oldDay =  MyUtil.getLastStr(caiPiaoEntity.getOldDay());
                    String newDay = MyUtil.getLastStr(caiPiaoEntity.getNewDay());
                    String ny = caiPiaoEntity.getNy();// 纳音就是五行，不需要转换
//                    String code = MyUtil.getLastStr(caiPiaoEntity.getCode().split("-")[0].split(",")[codeIndex]);
                    String code1 = caiPiaoEntity.getCode().replace("-",",");
                    String code = MyUtil.getLastStr(code1.split(",")[codeIndex]);


                    // 五行属性
                    String tgwx = wuXingRelationUtil.dataMap.get(tg);
                    String dzwx = wuXingRelationUtil.dataMap.get(dz);
                    String oldDaywx = wuXingRelationUtil.dataMap.get(oldDay);// 农历五行
                    String newDaywx = wuXingRelationUtil.dataMap.get(newDay);// 阳历五行
                    String codewx = wuXingRelationUtil.dataMap.get(code);// 开奖号码五行

                    String wx = "";// 五行合并，用于获取生克关系
                    if(czx == 0){
                        wx = tgwx + codewx;
                    }else if(czx == 1){
                        wx = dzwx + codewx;
                    }else if(czx == 2){
                        wx = oldDaywx + codewx;
                    }else if(czx == 3){
                        wx = newDaywx + codewx;
                    }else if(czx == 4){
                        wx = ny + codewx;
                    }

                    String fx = wuXingRelationUtil.wxskMap.get(wx);// 生克方向

//                    System.out.println(wx+"-"+fx);
                    System.out.println(fx);


                }


            }

        }



//        System.out.println(cntMap.toString());
    }


    /**
     * 相邻两行对比
     * @Param jiange 间隔，相邻就是1，相隔一行就是2，以此类推
     */
    public void xiangling(List<CaiPiaoEntity> list, int czxMax, int codeIndexMax,int jiange){
        for(int i = 0; i<= czxMax; i++){
            int czx = i;
            if(czx == 0){
                System.out.println("========= 0天干 =========");
            }else if(czx == 1){
                System.out.println("========= 1地支 =========");
            }else if(czx == 2){
                System.out.println("========= 2农历 =========");
            }else if(czx == 3){
                System.out.println("========= 3阳历 =========");
            }else if(czx == 4){
                System.out.println("========= 4纳音 =========");
            }
            for(int j = 0; j<= codeIndexMax; j++){
                int codeIndex = j;
                System.out.println("----- "+j+" ----- ");

                // 数据处理
//                for(CaiPiaoEntity caiPiaoEntity : list){
                for(int k =0; k< list.size() - jiange; k++){
                    CaiPiaoEntity caiPiaoEntity = list.get(k);
                    CaiPiaoEntity caiPiaoEntity2 = list.get(k+jiange);


                    String kjDate = caiPiaoEntity.getKjDate();
                    String tg = caiPiaoEntity.getTg();
                    String dz = caiPiaoEntity.getDz();
                    String oldDay =  MyUtil.getLastStr(caiPiaoEntity.getOldDay());
                    String newDay = MyUtil.getLastStr(caiPiaoEntity.getNewDay());
                    String ny = caiPiaoEntity.getNy();// 纳音就是五行，不需要转换


//                    String code = MyUtil.getLastStr(caiPiaoEntity2.getCode().split("-")[0].split(",")[codeIndex]);
                    String code1 = caiPiaoEntity.getCode().replace("-",",");
                    String code = MyUtil.getLastStr(code1.split(",")[codeIndex]);

                    // 五行属性
                    String tgwx = wuXingRelationUtil.dataMap.get(tg);
                    String dzwx = wuXingRelationUtil.dataMap.get(dz);
                    String oldDaywx = wuXingRelationUtil.dataMap.get(oldDay);// 农历五行
                    String newDaywx = wuXingRelationUtil.dataMap.get(newDay);// 阳历五行
                    String codewx = wuXingRelationUtil.dataMap.get(code);// 开奖号码五行


                    String wx = "";// 五行合并，用于获取生克关系
                    if(czx == 0){
                        wx = tgwx + codewx;
                    }else if(czx == 1){
                        wx = dzwx + codewx;
                    }else if(czx == 2){
                        wx = oldDaywx + codewx;
                    }else if(czx == 3){
                        wx = newDaywx + codewx;
                    }else if(czx == 4){
                        wx = ny + codewx;
                    }

                    String fx = wuXingRelationUtil.wxskMap.get(wx);// 生克方向

//                    System.out.println(wx+"-"+fx);
//                    System.out.println(kjDate+"-"+fx);
                    System.out.println(fx);


                }


            }

        }
    }






}
